package com.cloudcc.mobile.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cloudcc.mobile.R;
import com.cloudcc.mobile.entity.group.GroupInfo;
import com.cloudcc.mobile.manager.RunTimeManager;

public class GroupInfoAdapter extends BaseAdapter {
	private String mEns = RunTimeManager.getInstance().getlanguage();
	private Context context;
	private List<GroupInfo> list;
	private OnItemListener onItemListener;

	public void setOnItemtListener(OnItemListener onItemListener) {
		this.onItemListener = onItemListener;
		this.notifyDataSetChanged();
	}

	public GroupInfoAdapter(Context context) {
		this.context = context;
	}

	public void changeData(List<GroupInfo> list) {
		this.list = list;
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public GroupInfo getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.group_item, null);
			holder.img = (ImageView) convertView.findViewById(R.id.gourp_img);
			holder.name = (TextView) convertView.findViewById(R.id.group_name2);
			holder.all = (LinearLayout) convertView.findViewById(R.id.all);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		GroupInfo info = list.get(position);
		holder.all.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				onItemListener.zhengti(position);
			}
		});
		if (info.isSelect()) {
			holder.img.setImageResource(R.drawable.group_t);
		} else {
			holder.img.setImageResource(R.drawable.group_f);
		}
		if (info.getName() != null) {
			if ("en".equals(mEns)) {
				if ("朋友圈".equals(info.getName())) {
					holder.name.setText("Circle of friends");
				}else{
					holder.name.setText(info.getName());
				}
				
			}else{
				holder.name.setText(info.getName());
		}

			
		}
		return convertView;
	}

	public interface OnItemListener {
		public void zhengti(int position);
	}

	class ViewHolder {
		ImageView img;
		TextView name;
		LinearLayout all;
	}
}
